package com.cje.login;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @Auther: ChenJinEn
 * @Date: 2020/8/10 22:24
 * @Description: //TODO
 */
@WebListener
public class MyListener implements ServletContextListener {
    /**
     * @Author: ChenJinEn
     * @Date: 2020/8/10 22:31
     * @params: [servletContextEvent]
     * @return: void
     * @Description: //TODO 服务器启动时被调用,用于加载文件的操作
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("服务器启动了");

        //这些实质就是spring核心监听器的思想啊服务器启动前
        ServletContext servletContext = servletContextEvent.getServletContext();
        String contextConfigLocation = servletContext.getInitParameter("contextConfigLocation");
        String realPath = servletContext.getRealPath(contextConfigLocation);

        try {
            FileInputStream fileInputStream = new FileInputStream(realPath);
            //然后把这个资源交给spring去处理创建对象做ioc和aop的事情
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * @Author: ChenJinEn
     * @Date: 2020/8/10 22:32
     * @params: [servletContextEvent]
     * @return: void
     * @Description: //TODO 服务器销毁时被调用
     */
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("服务器销毁了");
    }
}
